<!--医院管理-->
<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <el-form ref="form" :model="detail" label-width="80px" class="form">
        <el-form-item label="所属医院">
          <el-select v-model="detail.hospitalId" class="input" placeholder="请选择">
            <el-option
              v-for="item in hospitalOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="医生名称">
          <el-input v-model="detail.name" />
        </el-form-item>
        <el-form-item label="排序">
          <el-input
            v-model="detail.sort"
            @input="detail.sort = detail.sort.replace(/[^\.\d]/g,'').replace('.','')"
          />
        </el-form-item>
        <el-form-item label="医生职位">
          <el-input v-model="detail.position" />
        </el-form-item>
        <el-form-item label="执证编号">
          <el-input type="textarea" v-model="detail.certificate" />
        </el-form-item>
        <el-form-item label="医生介绍">
          <el-input type="textarea" v-model="detail.introduce" />
        </el-form-item>
        <el-form-item label="医生图片">
          <div class="picList">
            <div class="item" v-for="(item,index) in fileListDoctor" :key="item.id+'fileListDoctor'">
              <img class="pic" :src="item.imgUrl" alt />
              <i class="el-icon-delete delIcon hand" @click="handleRemove(index,item.imgType)"></i>
            </div>
          </div>
          <div class="item itemNo" v-if="fileListDoctor.length < 1">
            <el-upload
              :action="Is.sevenDomain"
              :multiple="false"
              name="files"
              :limit="1"
              :data="{
              type:4
            }"
              :show-file-list="false"
              :before-upload="handleUpload"
              :on-success="handleSuccess"
            >
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，只能上传1张，且不超过10M</div>
              <div class="el-upload el-upload--picture-card">
                <i slot="default" class="el-icon-plus"></i>
              </div>
            </el-upload>
          </div>
        </el-form-item>
        <el-form-item label="项目案例">
          <div class="picList">
            <div class="item" v-for="(item,index) in fileListProject" :key="item.id+'fileListLogo'">
              <img class="pic" :src="item.imgUrl" alt />
              <i class="el-icon-delete delIcon hand" @click="handleRemove(index,item.imgType)"></i>
            </div>
            <div class="item itemNo" v-if="fileListProject.length < 6">
              <el-upload
                :action="Is.sevenDomain"
                :multiple="false"
                name="files"
                :limit="6"
                :data="{
                  type:5
                }"
                :show-file-list="false"
                :before-upload="handleUpload"
                :on-success="handleSuccess"
              >
                <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，只能上传1张，且不超过10M</div>
                <div class="el-upload el-upload--picture-card">
                  <i slot="default" class="el-icon-plus"></i>
                </div>
              </el-upload>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="擅长项目">
          <el-tag
            :key="tag"
            v-for="(tag,index) in detail.goodProject"
            closable
            :disable-transitions="false"
            @close="handleClose(index)"
          >{{tag}}</el-tag>
          <el-input
            class="input-new-tag"
            v-if="inputVisible"
            v-model="inputValue"
            ref="saveTagInput"
            size="small"
            @keyup.enter.native="handleInputConfirm"
            @blur="handleInputConfirm"
          ></el-input>
          <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 添加项目</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit">提交</el-button>
          <el-button @click="cancel">返回</el-button>
        </el-form-item>
      </el-form>
    </el-scrollbar>
  </section>
</template>
<script>
export default {
  data() {
    return {
      pagination: {
        pageSize: 10,
        page: 1,
        total: 0
      },
      detail: {
        name:'',
        status:null
      },
      statusOptions: [
        {
          value: null,
          label: '全部'
        },
        {
          value: 1,
          label: '正常'
        },
        {
          value: 0,
          label: '禁用'
        }],
      ids: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    editStatusSingle(type, id) {
      if (type == 1) {
        // 启用
        updateHospitalStatus({
          ids: [id],
          status: 1
        }).then(data => {
          Is.tip('启用成功')
          this.getList()
        })
      }
    },
    editStatusSingles(type){
      if(Is.empty(this.ids)){
        Is.tip('未选择编辑项')
        return false
      }
      if(type == 1){
        // 启用
        updateHospitalStatus({
          ids:this.ids,
          status:1
        }).then(data=>{
          Is.tip('启用成功')
          this.getList()
        })
      }
      if(type == 0){
        // 禁用
        updateHospitalStatus({
          ids:this.ids,
          status:0
        }).then(data=>{
          Is.tip('禁用成功')
          this.getList()
        })
      }
    },
    reset() {
      this.detail = {
        name:'',
        status:null,
      }
      this.pagination = {
        pageSize: 10,
        page: 1,
        total: 0
      }
      this.getList()
    },
    getList(){
      const params = {
        name:this.detail.name,
        status:this.detail.status,
        page:this.pagination.page,
        pageSize:this.pagination.pageSize
      }
      hospitalList(params).then(data=>{
        this.list = data.respPageBean.data
        this.pagination.total = data.respPageBean.total
        // this.list = data
      })
    },
    handleSelectAll(selection) {
      this.ids = []
      if(selection.length > 0){
        selection.forEach(item=>{
          this.ids.push(item.id)
        })
      }
    },
    handleCurrentChange(val) {
      // 重置当前页码
      this.pagination.page = val
      this.getList()
    },
    handleSelectionChange(selection){
      this.ids = []
      if(selection.length > 0){
        selection.forEach(item=>{
          this.ids.push(item.id)
        })
      }
    },
    // 多选删除
    toDels(){
      if(Is.empty(this.ids)){
        Is.tip('未选择删除项')
        return false
      }
      this.$confirm('确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delHospital(
          this.ids
        ).then(data=>{
          Is.tip('删除成功',1500,'success')
          if (this.list.length === this.ids.length && this.pagination.page > 1) {
            this.pagination.page--
          }
          this.getList()
        })
      })
    },
    // 单选删除
    toDel(id){
      this.$confirm('确认删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delHospital(
          [id]
        ).then(data=>{
          Is.tip('删除成功',1500,'success')
          if (this.list.length === 1 && this.pagination.page > 1) {
            this.pagination.page--
          }
          this.getList()
        })
      }).catch((e)=>{

      })
    }
  }}
</script>
